from django.contrib.auth.models import AbstractUser
from django.db import models

SEX_UNKNOWN = 0
SEX_MALE = 1
SEX_FEMALE = 2

SEX = (
    (SEX_UNKNOWN, '未知'),
    (SEX_MALE, '男'),
    (SEX_FEMALE, '女'),
)


# Create your models here.
class User(AbstractUser):
    app_open_id = models.CharField(max_length=100, null=True, blank=True, unique=True, verbose_name='服务号OpenId')
    mini_program_open_id = models.CharField(max_length=100, null=True, blank=True, unique=True,
                                            verbose_name='小程序OpenId')
    union_id = models.CharField(max_length=100, null=True, blank=True, unique=True, verbose_name='全局编号')
    sex = models.SmallIntegerField(choices=SEX, default=SEX_UNKNOWN, verbose_name='性别')
    nick_name = models.CharField(max_length=100, null=True, blank=True, unique=True, verbose_name='昵称')
    phone = models.CharField(max_length=100, null=True, blank=True, unique=True, verbose_name='手机号')
    last_login = models.DateTimeField(null=True, blank=True, verbose_name='最后登录时间')

    def __str__(self):
        return f'{self.id}-{self.first_name}'

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name
        db_table = 'auth_user'
